<?php

include_once YIFANG_ROOT."/version/Package.php";

class ExecScript
{
    /**
     * 安装脚本
     */
    public function install(){
        $package=data("cms.package");
        if($package){
            $version=str_replace(".","_",$package["version"]);
            $method="package_".$version;
            $obj=new Package();
            if(method_exists($obj,"boot")){
                $obj->boot();
            }
            if(method_exists($obj,$method)){
                $obj->$method();
            }
        }
        return true;
    }

    /**
     * 执行脚本
     */
    public function exec($method){
        $obj=new Package();
        if(method_exists($obj,$method)){
            $obj->$method();
        }
        return true;
    }

    /**
     * 获取方法名
     */
    public function getMethods(){
        $result=array();
        $class = new \ReflectionClass("Package");
        $methods = $class->getMethods();
        foreach ($methods as $method) {
            $result[]=$method->getName();
        }
        return $result;
    }
}